package com.hadoop.mr.score_statistics;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;

public class ScoreStaMaper extends Mapper<LongWritable, Text, Text, Student>{
	@Override
	protected void map(LongWritable key, Text value, org.apache.hadoop.mapreduce.Mapper.Context context)
			throws IOException, InterruptedException {
		Student stu = new Student();
		String arr[] = value.toString().split(" ");
		FileSplit split= (FileSplit) context.getInputSplit();
		stu.setName(arr[1]);
		stu.setScore(Integer.valueOf(arr[2]));
		if(split.getPath().getName().equals("chinese.txt")){
			stu.setSubject("chinese");
		} else if(split.getPath().getName().equals("english.txt")){
			stu.setSubject("english");
		} else if(split.getPath().getName().equals("math.txt")){
			stu.setSubject("math");
		}
		//System.out.println(stu.getSubject()+stu.getScore());
		context.write(new Text(arr[1]), stu);
	}

}
